package net.tw.transactional2.aop;

import lombok.extern.slf4j.Slf4j;
import net.tw.transactional2.task.TaskAService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@Aspect
@Slf4j
@Transactional
public class TransactionalAop {

    @Autowired
    TaskAService taskAService;

    @Around(value = "@annotation(net.tw.transactional2.annotation.Transactional2)")
    public Object around(ProceedingJoinPoint jp) throws Throwable {
        log.debug("TransactionalAop -- around before...");
        Object obj = taskAService.taskA(jp);
        log.debug("TransactionalAop -- around after...");
        return obj;
    }
}
